package kata;

public class Card implements Comparable<Card> {

	private int value;
	private Suit suit;

	public Card(String suitAndValue) {
		buildSuitAndValue(suitAndValue);
	}

	public int getValue() {
		return value;
	}

	public Suit getSuit() {
		return suit;
	}

	private void buildSuitAndValue(String card) {
		Character cardCharacter = card.charAt(0);

		if (cardCharacter == 'A') {
			value = 14;
			setSuit(card.charAt(1));
		} else if (cardCharacter == '1') {
			value = 10;
			setSuit(card.charAt(2));
		} else if (cardCharacter == 'J') {
			value = 11;
			setSuit(card.charAt(1));
		} else if (cardCharacter == 'Q') {
			value = 12;
			setSuit(card.charAt(1));
		} else if (cardCharacter == 'K') {
			value = 13;
			setSuit(card.charAt(1));
		} else {
			value = Integer.parseInt(cardCharacter.toString());
			setSuit(card.charAt(1));
		}
	}

	private void setSuit(char suit) {
		switch (suit) {
		case 'H':
			this.suit = Suit.Hearts;
			break;
		case 'D':
			this.suit = Suit.Diamonds;
			break;
		case 'S':
			this.suit = Suit.Spades;
			break;
		case 'C':
			this.suit = Suit.Clubs;
			break;
		}
	}

	@Override
	public int compareTo(Card otherCard) {
		return this.value - otherCard.getValue();
	}
}
